<template>
  <a-card :bordered="false">
  <a-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="取消">
    <a-spin :spinning="confirmLoading">

        <a-tab-pane  key="1" :forceRender="true">
          <!-- 查询区域 -->
          <div class="table-page-search-wrapper">
            <a-form layout="inline">
              <a-row :gutter="24">
                <a-col :md="6" :sm="8">
                  <a-form-item label="表名称">
                    <a-input placeholder="请输入表名称" v-model="queryParam.fdTablename"></a-input>
                  </a-form-item>
                </a-col>

                <a-col :md="6" :sm="8">
                  <a-form-item label="schema">
                    <a-input placeholder="请输入schema" v-model="queryParam.fdSchema"></a-input>
                  </a-form-item>
                </a-col>
                <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
                </a-col>

              </a-row>
            </a-form>
          </div>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :loading="loading"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
            @change="handleTableChange"></a-table>
        </a-tab-pane>

    </a-spin>
  </a-modal>
  </a-card>
</template>

<script>
  import { httpAction, postAction, getAction } from '@/api/manage'
  import { FormTypes, VALIDATE_NO_PASSED, getRefPromise, validateFormAndTables } from '@/utils/JEditableTableUtil'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'


  export default {

    name: 'AddTableinfoModal',
    mixins: [JeecgListMixin],

    data() {
      return {

        visible: false,
        model: {},
        //编辑信息

          columns: [
           /* {
              title: '表id',
              align:"center",
              dataIndex: 'fdTableid'
            },*/
            {
              title: '表名称',
              align:"center",
              dataIndex: 'fdTablename'
            },
            {
              title: '表描述',
              align:"center",
              dataIndex: 'fdTabledesc'
            },
            {
              title: 'schema',
              align:"center",
              dataIndex: 'fdSchema'
            },
            {
              title: '系统编号',
              align:"center",
              dataIndex: 'fdSysid'
            },
            {
              title: '表创建时间',
              align:"center",
              dataIndex: 'fdCreatetime'
            },
            {
              title: '状态',
              align:"center",
              dataIndex: 'fdStatus_dictText'
            },
            {
              title: '分区字段',
              align:"center",
              dataIndex: 'fdLoaddt'
            },

          ],


        confirmLoading: false,
        selectedRows: [],

        url: {
          list: '/rule/autossc/listSysTableinfo',
          add:'/rule/autossc/addAutosscDetail'
        }
      }
    },
    created: function() {
      this.queryParamConfig = { 'fdTablename': 'like','fdSchema':'like'  }
    },

    methods: {
      edit(fdSscid) {
        this.visible = true;
        this.activeKey = '1'
        this.model = Object.assign({},{id:fdSscid} )
        // 加载子表数据
        let params = { fdSscid: fdSscid }
        this.requestTableData(this.url.list, params, )

      },
      onSelectChange(selectedRowKeys, selectedRows) {
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectedRows;
      },

      /** 查询某个tab的数据 */
      requestTableData(url, params) {
        this.loading = true
        getAction(url, params).then(res => {
         this.dataSource = res.result.records || []
          this.ipagination.total = res.result.total;
        }).finally(() => {
          this. loading = false
        })
      },
      handleOk() {
        const that = this;
        let params = { fdSscid: this.model.id,fdTableId:this.selectionRows}
        postAction(this.url.add, params).then(res => {
          that.loading = true;
          if (res.success) {
            that.$message.success(res.message);
            that.$emit('ok');
          } else {
            that.$message.warning(res.message);
          }
        }).finally(() => {
          that.confirmLoading = false;
          that.close();
        })
      },
      handleCancel() {
        this.close()
      },
      close() {
        this.visible = false
        this.$emit('close')
      },
    }
  }
</script>

<style scoped>

</style>
